﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

/**
 * Make sure that you have added references to Visifire assembly, 
 * WPFVisifire.Charts.dll. Do not forget to include the Visifire.Charts 
 * and Visifire.Commons within any code file where you want to work 
 * with the charts. These files can be added with following syntax:
 * */
using Visifire.Charts;
using Visifire.Commons;

using System.Collections.ObjectModel;

using GasData;

using System.Threading;

// CancelEventArgs
using System.ComponentModel;

using System.IO;

namespace WPF_DataLogger
{
    /// <summary>
    /// Interaction logic for HistoryWindow.xaml
    /// </summary>
    public partial class HistoryWindow : Window
    {
        public HistoryWindow(String fpath)
        {
            InitializeComponent();
            UserComponentsInit(fpath);
        }

        private void UserComponentsInit(String fpath)
        {
            /*
            CO_series = new GasDataSeries("CO");
            GasDataPoint new_point = new GasDataPoint(DateTime.Now, 23.0);

            CO_series.AddDataPointEntry(new_point);

            new_point = new GasDataPoint(new DateTime(2008, 3, 9, 17, 5, 7, 123), 24.5);

            CO_series.AddDataPointEntry(new_point);
            */

            _archiveManager = new ArchiveParser(fpath);

            if (_archiveManager.LoadArchive() == false)
            {
                return;
            }

            //HistoryChart.Series[0].DataSource = CO_series.DataPoints;
            //HistoryChart.Series[0].LegendText = CO_series.SeriesName + " Series";
            for (int idx = 0; idx < HistoryChart.Series.Count; idx++)
            {
                HistoryChart.Series[idx].DataSource = _archiveManager.GetOneSeriesDataPoints(idx);
                HistoryChart.Series[idx].LegendText = _archiveManager.GetSeriesName(idx) + " series";
            }
        }

        public void Clear()
        {
            //CO_series.Cleanup();
            _archiveManager.Clear();
        }

        public void HistoryWindow_Closing(object sender, CancelEventArgs e)
        {
            this.Clear();
        }

        //private GasDataSeries CO_series;

        private ArchiveParser _archiveManager;
    }
}
